angular.module("sportsStore")
.constant("activeClass","btn-primary")//定义常量
.constant("productListPageCount",3)
.controller("productListCtrl",function($scope,$filter,activeClass,productListPageCount,cart){
    var selectdCategory=null;
    $scope.selectedPage=1;
    $scope.pageSize=productListPageCount;
    $scope.selectCategory = function(newCategory){
            selectdCategory = newCategory;
            $scope.selectedPage=1;
        }
 
    $scope.selectPage=function(newPage){
        $scope.selectedPage=newPage;
    }
    $scope.categoryFilterFn = function(product){
            return selectdCategory == null || product.category==selectdCategory;  //没有分类被选择或者产品属于被选中的分类时返回true
        }
    $scope.getCategoryClass=function(category){
        return category==selectdCategory?activeClass:"";
    }
    $scope.getPageClass=function(page){
        return $scope.selectedPage==page?activeClass:"";
    }

    $scope.addProductToCart=function(product){
        cart.addProduct(product.id,product.name,product.price);
    }
    

})

